package views;

import views.panels.PanelGeneral;
import java.awt.BorderLayout;
import logicBusiness.AulaBL;
import models.Aula;
import java.util.List;
import javax.swing.DefaultListModel;
import javax.swing.JOptionPane;


public class InterfazAdministrarAulas extends javax.swing.JFrame {
    private AulaBL bo = new AulaBL();
    private Aula a = new Aula();
    private int ok = 0;

    /** Creates new form InterfazAdministrarAulas */
    public InterfazAdministrarAulas() {
        initComponents();
        PanelGeneral panel = new PanelGeneral();
        this.add(panel, BorderLayout.SOUTH);
        iniciarListaAulas();
        BEliminarAula.setEnabled(false);
        BEditarAula.setEnabled(false);
        BConsultaAula.setEnabled(false);
        CTEdiCapAula.setEnabled(false);
        CTEdiNomAula.setEnabled(false);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        buttonGroup2 = new javax.swing.ButtonGroup();
        jLabel1 = new javax.swing.JLabel();
        BEliminarAula = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        CTNomAula = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        CTCapAula = new javax.swing.JTextField();
        BCrearAula = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jLabel5 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        BConsultaAula = new javax.swing.JButton();
        BEditarAula = new javax.swing.JButton();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        CTSalidaNomAula = new javax.swing.JTextField();
        CTSalidaCapAula = new javax.swing.JTextField();
        CTSalidaDisponible = new javax.swing.JTextField();
        jLabel14 = new javax.swing.JLabel();
        CTEdiNomAula = new javax.swing.JTextField();
        jLabel15 = new javax.swing.JLabel();
        CTEdiCapAula = new javax.swing.JTextField();
        jLabel16 = new javax.swing.JLabel();
        BConsultaGeneral = new javax.swing.JButton();
        SPAulas = new javax.swing.JScrollPane();
        ListaAulas = new javax.swing.JList();
        BLimpiarLista = new javax.swing.JButton();
        JRSi1 = new javax.swing.JRadioButton();
        JRNo1 = new javax.swing.JRadioButton();
        JRSi2 = new javax.swing.JRadioButton();
        JRNo2 = new javax.swing.JRadioButton();
        etiqueta1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();

        setResizable(false);

        jLabel1.setText("Crear un Aula");

        BEliminarAula.setText("Eliminar Aula");
        BEliminarAula.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BEliminarAulaActionPerformed(evt);
            }
        });

        jLabel3.setText("Nombre del Aula:");

        jLabel4.setText("Capacidad del Aula:");

        BCrearAula.setText("Crear Aula");
        BCrearAula.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BCrearAulaActionPerformed(evt);
            }
        });

        jButton3.setText("Volver al menu");
        jButton3.setActionCommand("Volver");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jLabel5.setText("Disponible");

        jLabel9.setText("Consultar individual de Aula");

        BConsultaAula.setText("Consultar Aula");
        BConsultaAula.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BConsultaAulaActionPerformed(evt);
            }
        });

        BEditarAula.setText("Editar Aula");
        BEditarAula.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BEditarAulaActionPerformed(evt);
            }
        });

        jLabel10.setText("Nombre del Aula:");

        jLabel11.setText("Capacidad del Aula");

        jLabel12.setText("Disponible");

        CTSalidaNomAula.setEditable(false);

        CTSalidaCapAula.setEditable(false);

        CTSalidaDisponible.setEditable(false);

        jLabel14.setText("Nombre del Aula:");

        jLabel15.setText("Capacidad del Aula:");

        jLabel16.setText("Disponible");

        BConsultaGeneral.setText("Consulta general");
        BConsultaGeneral.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BConsultaGeneralActionPerformed(evt);
            }
        });

        ListaAulas.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                ListaAulasMouseClicked(evt);
            }
        });
        SPAulas.setViewportView(ListaAulas);

        BLimpiarLista.setText("Limpiar lista");
        BLimpiarLista.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BLimpiarListaActionPerformed(evt);
            }
        });

        JRSi1.setText("Si");
        JRSi1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JRSi1ActionPerformed(evt);
            }
        });

        JRNo1.setText("No");
        JRNo1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JRNo1ActionPerformed(evt);
            }
        });

        JRSi2.setText("Si");
        JRSi2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JRSi2ActionPerformed(evt);
            }
        });

        JRNo2.setText("No");
        JRNo2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JRNo2ActionPerformed(evt);
            }
        });

        etiqueta1.setText("Lista de aulas registradas en el sistema");

        jLabel2.setText("Edición de Aula");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(BCrearAula, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 169, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGroup(layout.createSequentialGroup()
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(jLabel4)
                                .addComponent(jLabel1)
                                .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(CTCapAula, javax.swing.GroupLayout.PREFERRED_SIZE, 114, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(CTNomAula, javax.swing.GroupLayout.PREFERRED_SIZE, 123, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGap(6, 6, 6)))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(JRNo1)
                            .addComponent(JRSi1)))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel9)
                        .addGap(30, 30, 30)
                        .addComponent(BConsultaAula, javax.swing.GroupLayout.PREFERRED_SIZE, 160, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel10)
                            .addComponent(jLabel11)
                            .addComponent(jLabel12))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(CTSalidaCapAula)
                            .addComponent(CTSalidaDisponible)
                            .addComponent(CTSalidaNomAula, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 217, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(SPAulas, javax.swing.GroupLayout.Alignment.LEADING, 0, 0, Short.MAX_VALUE)
                            .addComponent(etiqueta1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(BConsultaGeneral, javax.swing.GroupLayout.PREFERRED_SIZE, 121, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(BEliminarAula, javax.swing.GroupLayout.PREFERRED_SIZE, 121, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(BLimpiarLista, javax.swing.GroupLayout.PREFERRED_SIZE, 117, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addComponent(jLabel2)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel15)
                        .addGap(18, 18, 18)
                        .addComponent(CTEdiCapAula, javax.swing.GroupLayout.PREFERRED_SIZE, 114, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel16, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(JRSi2)
                            .addComponent(JRNo2)))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel14, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(CTEdiNomAula, javax.swing.GroupLayout.PREFERRED_SIZE, 123, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(76, 76, 76)
                        .addComponent(BEditarAula, javax.swing.GroupLayout.PREFERRED_SIZE, 160, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(184, Short.MAX_VALUE))
            .addGroup(layout.createSequentialGroup()
                .addGap(257, 257, 257)
                .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 241, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(668, Short.MAX_VALUE))
        );

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {CTCapAula, CTNomAula});

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {CTEdiCapAula, CTEdiNomAula});

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jLabel3, jLabel4, jLabel5});

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jLabel14, jLabel15, jLabel16});

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {JRNo1, JRSi1});

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {JRNo2, JRSi2});

        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jLabel3)
                                .addGap(6, 6, 6))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(CTNomAula, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)))
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel4)
                            .addComponent(CTCapAula, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel5)
                            .addComponent(JRSi1))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(JRNo1)
                        .addGap(10, 10, 10)
                        .addComponent(BCrearAula))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(etiqueta1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(BConsultaGeneral)
                                .addGap(18, 18, 18)
                                .addComponent(BLimpiarLista)
                                .addGap(18, 18, 18)
                                .addComponent(BEliminarAula))
                            .addComponent(SPAulas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(55, 55, 55)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, 13, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(BConsultaAula))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel10)
                            .addComponent(CTSalidaNomAula, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel11)
                            .addComponent(CTSalidaCapAula, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel12)
                            .addComponent(CTSalidaDisponible, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(49, 49, 49)
                        .addComponent(jLabel2)
                        .addGap(28, 28, 28)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel14)
                            .addComponent(CTEdiNomAula, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(6, 6, 6)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel15)
                            .addComponent(CTEdiCapAula, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(JRSi2)
                            .addComponent(jLabel16))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(JRNo2)
                        .addGap(18, 18, 18)
                        .addComponent(BEditarAula)))
                .addGap(99, 99, 99)
                .addComponent(jButton3)
                .addContainerGap(55, Short.MAX_VALUE))
        );

        layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {CTEdiCapAula, CTEdiNomAula});

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        this.setVisible(false);
    }//GEN-LAST:event_jButton3ActionPerformed
    /**
     * Este metodo primero valida que los campos necesarios para la creacion de un aula
     * no se encuentren vacios, el uso de los radio button (b_si1 y b_no1) es para manejar la disponibilidad
     * del aula se invoca al metodo crearAula de la clase AulaBL y se retroalimenta al usuario informadole si su
     * transaccion fue o no fue exitosa
     */
    private void BCrearAulaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BCrearAulaActionPerformed
        int disponible = 0;
        if (CTNomAula.getText().equals("") || CTCapAula.getText().equals("")) {
            JOptionPane.showMessageDialog(this, "Debe digitar los datos completos para crear un Aula", null, JOptionPane.ERROR_MESSAGE);
        } else {
            if (JRSi1.isSelected() == true) {
                disponible = 1;
            } else if (JRNo1.isSelected() == true) {
                disponible = 0;
            }
            ok = bo.crearAula(CTNomAula.getText(), Integer.parseInt(CTCapAula.getText()), disponible);
            CTNomAula.setText("");
            CTCapAula.setText("");

            if (ok == 1) {
                JOptionPane.showMessageDialog(this, "Se ha creado el aula con exito", "Creacion exitosa !!!", JOptionPane.INFORMATION_MESSAGE);
            } else {
                JOptionPane.showMessageDialog(this, "Ocurrio un error al crear el aula", "Creacion fallida", JOptionPane.ERROR_MESSAGE);
            }
        }
        BEliminarAula.setEnabled(false);
        BEditarAula.setEnabled(false);
        BConsultaAula.setEnabled(false);
        CTEdiCapAula.setEnabled(false);
        CTEdiNomAula.setEnabled(false);
        iniciarListaAulas();
    }//GEN-LAST:event_BCrearAulaActionPerformed

    private void BEliminarAulaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BEliminarAulaActionPerformed
        if (ListaAulas.getSelectedIndex() == -1) {
            JOptionPane.showMessageDialog(this, "Debe seleccionar un aula de la lista para eliminar un Aula", null, JOptionPane.ERROR_MESSAGE);
        } else {
            ok = bo.encontrarAula(ListaAulas.getSelectedValue() + "");
            if (ok != 0) {
                bo.borrarAula(ok);
                JOptionPane.showMessageDialog(this, "Se ha eliminado el aula con exito", "Eliminacion exitosa ", JOptionPane.INFORMATION_MESSAGE);
            } else {
                JOptionPane.showMessageDialog(this, "Ocurrio un error al eliminar el aula", "Eliminacion fallida", JOptionPane.ERROR_MESSAGE);
            }
        }
        BEliminarAula.setEnabled(false);
        BEditarAula.setEnabled(false);
        BConsultaAula.setEnabled(false);
        CTEdiCapAula.setEnabled(false);
        CTEdiNomAula.setEnabled(false);
        iniciarListaAulas();
    }//GEN-LAST:event_BEliminarAulaActionPerformed

    private void BConsultaAulaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BConsultaAulaActionPerformed

        Integer id = 0;
        if (ListaAulas.getSelectedIndex() == -1) {
            JOptionPane.showMessageDialog(this, "Debe seleccionar un aula de la lista para eliminar un Aula", null, JOptionPane.ERROR_MESSAGE);
        } else {
            id = bo.encontrarAula(ListaAulas.getSelectedValue() + "");
            if (id != 0) {
                id = bo.encontrarAula(ListaAulas.getSelectedValue() + "");
                a = bo.consultarAula(id);
                CTSalidaNomAula.setText(a.getNombreAula());
//                CTSalidaCapAula.setText(a.getCapacidadAula() + "");
                if (1==1/*a.getDisponibleAula() == 1*/) {
                    CTSalidaDisponible.setText("Si");
                } else {
                    CTSalidaDisponible.setText("No");

                }
            } else {
                JOptionPane.showMessageDialog(this, "Ocurrio un error al consultar el aula", "No se encontro aula", JOptionPane.ERROR_MESSAGE);
            }
        }
        BEliminarAula.setEnabled(false);
        BEditarAula.setEnabled(false);
        BConsultaAula.setEnabled(false);
        CTEdiCapAula.setEnabled(false);
        CTEdiNomAula.setEnabled(false);
        iniciarListaAulas();
    }//GEN-LAST:event_BConsultaAulaActionPerformed

    private void BEditarAulaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BEditarAulaActionPerformed
        Integer disponible = 0, id = 0;
        if (ListaAulas.getSelectedIndex() == -1) {
            JOptionPane.showMessageDialog(this, "Debe seleccionar un aula de la lista para eliminar un Aula", null, JOptionPane.ERROR_MESSAGE);
        } else {
            id = bo.encontrarAula(ListaAulas.getSelectedValue() + "");
            if (id != 0) {
                if (JRSi2.isSelected() == true) {
                    disponible = 1;
                } else if (JRNo2.isSelected() == true) {
                    disponible = 0;
                }
                ok = bo.actualizarAula(id, CTEdiNomAula.getText(), Integer.parseInt(CTEdiCapAula.getText()), disponible);
                CTEdiNomAula.setText("");
                CTEdiCapAula.setText("");
                if (ok == 1) {
                    JOptionPane.showMessageDialog(this, "Se ha Actualizado el aula con exito", "Actualizacion exitosa", JOptionPane.INFORMATION_MESSAGE);
                } else {
                    JOptionPane.showMessageDialog(this, "Ocurrio un error al editar el aula", "Actualizacion fallida =(", JOptionPane.ERROR_MESSAGE);
                }
            }
        }
        BEliminarAula.setEnabled(false);
        BEditarAula.setEnabled(false);
        BConsultaAula.setEnabled(false);
        CTEdiCapAula.setEnabled(false);
        CTEdiNomAula.setEnabled(false);
        iniciarListaAulas();
    }//GEN-LAST:event_BEditarAulaActionPerformed

    private void BConsultaGeneralActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BConsultaGeneralActionPerformed

        List l = bo.consultarAulas();
        DefaultListModel modelo = new DefaultListModel();
        for (int i = 0; i < l.size(); i++) {
            modelo.addElement(l.get(i) + "");
        }
        ListaAulas.setModel(modelo);
    }//GEN-LAST:event_BConsultaGeneralActionPerformed

    private void ListaAulasMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_ListaAulasMouseClicked
        BEditarAula.setEnabled(true);
        CTEdiCapAula.setEnabled(true);
        CTEdiNomAula.setEnabled(true);
        BEliminarAula.setEnabled(true);
        BConsultaAula.setEnabled(true);
    }//GEN-LAST:event_ListaAulasMouseClicked

    private void BLimpiarListaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BLimpiarListaActionPerformed
        DefaultListModel modelo = (DefaultListModel) ListaAulas.getModel();
        modelo.clear();
        ListaAulas.setModel(modelo);

    }//GEN-LAST:event_BLimpiarListaActionPerformed

    private void JRSi1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JRSi1ActionPerformed
        if (JRSi1.isSelected() == true) {
            JRNo1.setEnabled(false);
        } else if (JRSi1.isSelected() == false) {
            JRNo1.setEnabled(true);
        }
    }//GEN-LAST:event_JRSi1ActionPerformed

    private void JRNo1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JRNo1ActionPerformed
        if (JRNo1.isSelected() == true) {
            JRSi1.setEnabled(false);
        } else if (JRNo1.isSelected() == false) {
            JRSi1.setEnabled(true);
        }
    }//GEN-LAST:event_JRNo1ActionPerformed

    private void JRSi2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JRSi2ActionPerformed
        if (JRSi2.isSelected() == true) {
            JRNo2.setEnabled(false);
        } else if (JRSi2.isSelected() == false) {
            JRNo2.setEnabled(true);
        }
    }//GEN-LAST:event_JRSi2ActionPerformed

    private void JRNo2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JRNo2ActionPerformed
        if (JRNo2.isSelected() == true) {
            JRSi2.setEnabled(false);
        } else if (JRNo2.isSelected() == false) {
            JRSi2.setEnabled(true);
        }
    }//GEN-LAST:event_JRNo2ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new InterfazAdministrarAulas().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton BConsultaAula;
    private javax.swing.JButton BConsultaGeneral;
    private javax.swing.JButton BCrearAula;
    private javax.swing.JButton BEditarAula;
    private javax.swing.JButton BEliminarAula;
    private javax.swing.JButton BLimpiarLista;
    private javax.swing.JTextField CTCapAula;
    private javax.swing.JTextField CTEdiCapAula;
    private javax.swing.JTextField CTEdiNomAula;
    private javax.swing.JTextField CTNomAula;
    private javax.swing.JTextField CTSalidaCapAula;
    private javax.swing.JTextField CTSalidaDisponible;
    private javax.swing.JTextField CTSalidaNomAula;
    private javax.swing.JRadioButton JRNo1;
    private javax.swing.JRadioButton JRNo2;
    private javax.swing.JRadioButton JRSi1;
    private javax.swing.JRadioButton JRSi2;
    private javax.swing.JList ListaAulas;
    private javax.swing.JScrollPane SPAulas;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.ButtonGroup buttonGroup2;
    private javax.swing.JLabel etiqueta1;
    private javax.swing.JButton jButton3;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel9;
    // End of variables declaration//GEN-END:variables

    private void iniciarListaAulas() {
        List l = bo.consultarAulas();
        DefaultListModel modelo = new DefaultListModel();
        for (int i = 0; i
                < l.size(); i++) {
            modelo.addElement(l.get(i) + "");
        }

        ListaAulas.setModel(modelo);
    }
}
